﻿using DevExpress.XtraEditors;
using MDK.Winform.UserControl.Config;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace MDK.Winform.UserControl
{
    public partial class ucTrackbarControl : XtraUserControl
    {
        private int _EditValue;
        private string _MonikerString;
        private VideoProcAmpProperty _video;
        public int EditValue
        {
            get { return _EditValue; }
            set
            {
                _EditValue = value;
                this.OnPropertyChanged(new EventArgs());
                //每次改变Name值调用方法;            
            }
        }

        private void OnPropertyChanged(EventArgs eventArgs)
        {
            if (!string.IsNullOrEmpty(_MonikerString))
            {
                track1.Value = EditValue;
                txt1.Value = EditValue;
                CameraParameterSet.SetCameraProcAmp(_MonikerString, _video, EditValue, VideoProcAmpFlags.Manual);
            }
        }

        public ucTrackbarControl()
        {
            InitializeComponent();
        }
        public void SetTrackValue(string MonikerString, VideoProcAmpProperty video, int min, int max)
        {
            _MonikerString = MonikerString;
            _video = video;
            track1.Properties.Minimum = min;
            track1.Properties.Maximum = max;
            txt1.Properties.MinValue = min;
            txt1.Properties.MaxValue = max;
        }

        private void track1_EditValueChanged(object sender, EventArgs e)
        {
            txt1.Value = track1.Value;
            EditValue = track1.Value;
        }

        private void txt1_EditValueChanged(object sender, EventArgs e)
        {
            track1.Value = decimal.ToInt32(txt1.Value);
            EditValue = track1.Value;
        }
    }
}
